package plug.LinkWordsPlugin;

import java.awt.Dimension;
import java.awt.Graphics;
import java.util.ArrayList;

import javax.swing.JPanel;

@SuppressWarnings("serial")
public class LinkWordsGraphicPanel extends JPanel {

	private ArrayList<Integer> px, py;

	public LinkWordsGraphicPanel(int hauteur) {

		this.setPreferredSize(new Dimension(100, hauteur));

		px = new ArrayList<Integer> ();
		py = new ArrayList<Integer> ();

	}

	/**Cette methode dessine les liaisons entre les mots.**/
	public void draw(int x, int y) {
		px.add(x);
		py.add(y);
	}

	/**Cette methode supprime les liaisons en trop.**/
	public void erase(int indexX, int indexY) {

		if (px.contains(indexX)) {

			int index = px.indexOf(indexX);

			px.remove(index);
			py.remove(index);

		}
		if (py.contains(indexY)) {

			int index = py.indexOf(indexY);

			px.remove(index);
			py.remove(index);

		}

	}

	public void paintComponent(Graphics g) {

		for (int i=0; i<px.size(); i++) {
			g.drawLine(0, 15 + px.get(i)*18, this.getWidth(), 15 + py.get(i)*18);
		}

	}

}
